package com.company.indicationshots.util;
//二进制字符串转十六进制字符串
public class BinaryToHexConverter {
    public static String binaryToHex(String binary){
        String bin1 = binary.substring(0, 4);
        String bin2 = binary.substring(4);
        String hex1 = binaryMatchHex(bin1);
        String hex2 = binaryMatchHex(bin2);
        return hex1 + hex2;
    }

    public static String binaryMatchHex(String binary){
        String hex = null;
        switch (binary)
        {
            case "0000":
                hex = "0";
                break;
            case "0001":
                hex = "1";
                break;
            case "0010":
                hex = "2";
                break;
            case "0011":
                hex = "3";
                break;
            case "0100":
                hex = "4";
                break;
            case "0101":
                hex = "5";
                break;
            case "0110":
                hex = "6";
                break;
            case "0111":
                hex = "7";
                break;
            case "1000":
                hex = "8";
                break;
            case "1001":
                hex = "9";
                break;
            case "1010":
                hex = "A";
                break;
            case "1011":
                hex = "B";
                break;
            case "1100":
                hex = "C";
                break;
            case "1101":
                hex = "D";
                break;
            case "1110":
                hex = "E";
                break;
            case "1111":
                hex = "F";
                break;
        }
        return hex;
    }

}
